package com.cskaoyan.javase.review.string;

/**
 * @description: String Demo
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

public class Demo {
    public static void main(String[] args) {
        /*//s1，s2指向的对象在字符串常量池中
        String s1 = "hello world!";
        String s2 = "hello world!";
        System.out.println(s1 == s2);*/

       /* String s1 = "Hello";
        String s2 = "Hello";
        String s3 = "Hel" + "lo";
        String s4 = "Hel" + new String("lo");
        String s5 = new String("Hello");
        String s7 = "H";
        String s8 = "ello";
        String s9 = s7 + s8;

        System.out.println(s1 == s2); //true
        System.out.println(s1 == s3); //true
        System.out.println(s1 == s4); //false
        System.out.println(s1 == s9); //false
        System.out.println(s4 == s5); //false*/

        /*String s1 = "Hello";
        String s2 = new String("Hello");
        String s3 = new String("World");
        String s4 = s2 + s3;

        System.out.println(s1 == s2.intern());  //true
        System.out.println(s2 == s2.intern()); // 等同于 s2 == s1 false
        System.out.println(s3 == s3.intern()); //false 字符串常量池中已经存在"World"对象,再intern直接返回它的引用
        System.out.println(s4 == s4.intern()); // true 等同于 s4 == s4*/

        //new StringBuilder("计算机").append("软件").toString() 在堆上创建了一个"计算机软件"字符串
       /* String str1 = new StringBuilder("计算机").append("软件").toString();
        System.out.println(str1.intern() == str1); //等同于 str1 == str1 true

        //在堆上创建了"java"字符串对象
        String str2 = new StringBuilder("ja").append("va").toString();
        *//**
         * 按照一般理解这里等同于 str2 == str2 应该结果是true,这是在常量池中没有"java"字符串的情况下得出的结论
         * 但是实际上程序的结果是false,这说明常量池中已经有"java"字符串了
         *//*
        System.out.println(str2.intern() == str2);*/


        Integer i1 = 400;
        Integer i2 = 400;
        System.out.println(i1 == i2);

        Integer i3 = 0;
        System.out.println(i2 == (i2 + i3));

        Integer i4 = 100;
        Integer i5 = 100;
        System.out.println(i4 == i5);


        //String s = "" + 1;

    }
}
